﻿@model Zatify.WebUI.Admin.Models.SystemUsersListViewModel
@using (Html.BeginForm("Update", "SystemUsers"))
{ 
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                {
                    <th>
                    </th>
                    <th>
                        Actions
                    </th>
                }
                <th>
                    User ID
                </th>
                <th>
                    Email
                </th>
                <th>
                    Phone
                </th>
                <th>
                    Role
                </th>
                <th>
                    Status
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var user in Model.Users)
            {
                if (user.SystemUserId == Model.SelectedSystemUserID)
                { 
                <tr>
                    @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                    {
                        <td>
                            <input type="checkbox" class="userCheck" disabled="disabled" />
                        </td>
                        <td>
                            @Html.Hidden("user.SystemUserId", user.SystemUserId)
                            @Html.Hidden("user.Login", user.Login)

                            @Html.Hidden("page", Model.PagingInfo.CurrentPage)
                            @Html.Hidden("searchSystemUserModel.UserID", Model.SearchModel.SystemUserID)
                            @Html.Hidden("searchSystemUserModel.Email", Model.SearchModel.Email)
                            @Html.Hidden("searchSystemUserModel.Phone", Model.SearchModel.Phone)

                            <input type="image" src="@Url.Content("~/Areas/Admin/Content/zatify/Images/ok.png")" title="Save" style="width: 16px; height: 16px;" />
                            <a href="@Url.Action("List", new
                                {
                                    page = Model.PagingInfo.CurrentPage,
                                    systemUserID = Model.SearchModel.SystemUserID,
                                    email = Model.SearchModel.Email,
                                    phone = Model.SearchModel.Phone
                                })">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/cancel.png")" alt="Cancel" title="Cancel" style="width: 16px; height: 16px;" />
                            </a>
                        </td>
                    }
                    <td>
                        @user.Login
                    </td>
                    <td>
                        @Html.EditorFor(x => user.Email)
                    </td>
                    <td>
                        @Html.EditorFor(x => user.Phone)
                    </td>
                    <td>
                        @Html.DropDownListFor(x => user.Role, (IEnumerable<SelectListItem>)ViewData["Roles"])
                    </td>
                    <td>
                        @Html.EditorFor(x => user.IsActive)
                    </td>
                </tr>
                }
                else
                {
                <tr>
                    @if (Model.CurrentUserRole == Zatify.Domain.Abstract.UserRole.SystemAdmin)
                    {
                        <td>
                            <input type="checkbox" class="userChecked" value="@user.SystemUserId" />
                        </td>
                        <td>
                            <a href="@Url.Action("List", new
                                {
                                    page = Model.PagingInfo.CurrentPage,
                                    id = user.SystemUserId,
                                    systemUserID = Model.SearchModel.SystemUserID,
                                    email = Model.SearchModel.Email,
                                    phone = Model.SearchModel.Phone
                                })" title="Edit">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/edit_icon.png")" alt="Edit" />
                            </a><a href="@Url.Action("Delete", new { id = user.SystemUserId })" title="Delete"  onclick="return confirm('Are you sure you want to delete this system user?');">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/delete_icon.gif")" alt="Delete" />
                            </a><a href="#" title="Change password" onclick="changePassword(@user.SystemUserId)">
                                <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/password_icon.png")" alt="Change password" />
                            </a>
                            @if (user.IsActive)
                            {
                                <a href="@Url.Action("ChangeUserStatus", new { page = 1, id = user.SystemUserId, activate = 0 })" title="Inactivate" onclick="return confirm('Are you sure you want to Inactivate this system user?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/active_icon.png")" alt="Inactivate" />
                                </a>
                            }
                            else
                            {
                                <a href="@Url.Action("ChangeUserStatus", new { page = 1, id = user.SystemUserId, activate = 1 })" title="Activate" onclick="return confirm('Are you sure you want to Activate this system user?');">
                                    <img src="@Url.Content("~/Areas/Admin/Content/zatify/Images/suspend_icon.png")" alt="Activate" />
                                </a>
                            }
                        </td>
                    }
                    <td>
                        @user.Login
                    </td>
                    <td>
                        @user.Email
                    </td>
                    <td>
                        @user.Phone
                    </td>
                    <td>
                        @user.Role
                    </td>
                    <td>
                        @(user.IsActive ? "Active" : "Inactive")
                    </td>
                </tr>
                }
            }
        </tbody>
    </table>
}